import java.util.LinkedList;
import java.util.Queue;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    int[] dx = {0, 0, 1, -1};
    int[] dy = {1, -1, 0, 0};
    public int[][] floodFill(int[][] image, int sr, int sc, int color) {
        int prev = image[sr][sc];
        if(prev == color) return image;
        int m = image.length, n = image[0].length;
        Queue<int[]> queue = new LinkedList();
        queue.offer(new int[]{sr, sc});
        while(!queue.isEmpty()){
            int[] poll = queue.poll();
            image[poll[0]][poll[1]] = color;//修改颜色
            for (int i = 0; i < 4; i++) {
                int x = dx[i] + poll[0];
                int y = dy[i] + poll[1];
                if(x >= 0 && x < m && y >= 0 && y < n && image[x][y] == prev){
                    queue.offer(new int[]{x, y});
                }
            }
        }
        return image;
    }
}